/**
 * Created by liweizhao on 2017/4/28.
 */
window.onload = function () {
    getContent();

};


//动态加载文章列表
function getContent() {
    var j = 1;
    var timer = setInterval(function () {
        var boxBottom = parseFloat($('#contentBox').height() + $('#contentBox').offset().top);
        var viewBottom = parseFloat($(document).scrollTop() + $(window).height());
        if ((boxBottom - viewBottom) <= 0) {
            var getJson = {page: j};
            //根据URL获取文章筛选条件
            var articleClass = getQueryString('class');
            var articleDate = getQueryString('date');
            if (articleClass) {
                getJson.class = articleClass;
            }
            if (articleDate) {
                getJson.date = articleDate;
            }
            $.get("/article/getcontent", getJson, function (data) {
                    if (data.status) {
                        var Returnhtml = '';
                        $.each(data.data, function (a, b) {
                            Returnhtml = Returnhtml + '<div class="col-sm-12">' +
                                '<h3 class="clearfix post-title">' +
                                '<a href="/article/read.html?id=' + b.id + '" class="pull-left">' + b.title + '</a>' +
                                '<span class="pull-right">' + b.cd + '</span>' +
                                '</h3>' +
                                '<p>' + b.content + '</p>' +
                                '<div class="col-sm-12 row">' +
                                '<strong>' +
                                '<span style="color:#526DA5" class="fa fa-heart"> 赞: ' + b.like_num + '</span>' +
                                '<span style="margin-left: 20px"></span>' +
                                '<span style="color:#526DA5" class="fa fa-eye"> 阅: ' + b.browse_num + '</span>' +
                                '</strong>' +
                                '</div>' +
                                '<div class="row">' +
                                '<div class="col-sm-3">' +
                                '<a href="/article/read.html?id=' + b.id + '" class="btn btn-default">阅读更多</a>' +
                                '</div>' +
                                '</div>' +
                                '</div>'
                        });
                        $('#contentBox').append(Returnhtml);
                    } else {
                        var getInfo = '<button class="btu">' + data.info + '</button>';
                        $('#contentBox').append(getInfo);
                        clearTimeout(timer);
                        return false;
                    }

                }
            );

            j++;
        } else {
            return false;
        }
    }, '500');
}